<template>
	<view class="box">
		<!-- 设置 -->
		<view class="tou topNoBg" :style="'padding-top:' + statusBarHeight1 + 'px'" style="background: transparent;">
			<image @click="fanhui" class="image1" src="https://pic.bangbangtongcheng.com/static/seting-fanhui.png" />设置
		</view>
		<scroll-view scroll-y="true" :style="'height: calc(100vh - ' + curTop + 'px );'" class="list">
			<view class="touxiang" @click="us(1)" style="border-top: 2rpx solid #e0e0e0;">
				<span>关于我们</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>
			<view class="touxiang" @click="p" v-if="userInfo.phone">
				<span>问题反馈</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>
			<view class="touxiang" @click="tiaozhuan(1)" v-if="userInfo.phone">
				<span>举报管理</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>
			<view class="touxiang" @click="tiaozhuan(2)" v-if="userInfo.phone">
				<span>屏蔽名单</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>
			<view class="touxiang" @click="us(6)">
				<span>版权信息</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>
			<view class="touxiang" @click="xieyi(3)">
				<span>用户协议</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>

			<view class="touxiang" @click="toAccountSet">
				<span>账号管理</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>
			<!-- #ifdef APP-PLUS -->
			<view class="touxiang" @click="clearStorage">
				<span>清除缓存</span>
				<view class="huancun">
					<span style="right: 100rpx; top: 30rpx; left: auto">{{ storageSize }}</span>
					<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
				</view>
			</view>
			<!-- #endif -->
			<view class="touxiang" @click="SwitchA">
				<span>推送通知</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>
			<view class="touxiang">
				<span>当前版本</span>
				<span style="right: 30rpx; top: 30rpx; left: auto">{{ appversion }}</span>
			</view>
			<view class="touxiang" @click="zzzzAncjwt(2)">
				<span>证照资质</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>
			<view class="touxiang" @click="zzzzAncjwt(1)">
				<span>常见问题</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>
			<view class="touxiang" @click="xieyi(2)">
				<span>隐私政策</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>

			<view class="touxiang" @click="withdrawalPrivacy">
				<span>撤回同意隐私政策授权</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view>

			<view class="touxiang" style="display: none;">
				<span>推荐设置</span>

				<!-- #ifdef MP -->
				<switch @change="SwitchA" :checked="switchA" />
				<!-- #endif -->
				<!-- #ifdef APP-PLUS || H5 -->
				<switch @change="SwitchA" :checked="switchA" />
				<!-- #endif -->
			</view>
			<!-- <view class="touxiang" @click="clause" v-if="userInfo.phone">
				<span>账号注销</span>
				<image class="img2" src="https://pic.bangbangtongcheng.com/static/you.png" />
			</view> -->
		</scroll-view>
		<view class="switchAccounts" @click="switchAccounts" v-if="userInfo.phone">切换账号</view>
		<!-- <view class="logout" @click="logout" v-if="userInfo.phone">退出登录</view> -->
		<view class="motaikuang" v-show="show" @click="(show = false)">
			<view class="shangjia">
				<view class="li_1" style="text-align: center">是否确认{{ switchA ? '关闭' : '开启' }}消息推送？</view>
				<view v-show="switchA" class="li_1" style="font-size: 26rpx; color: #999; margin-top: 15rpx">
					关闭后您将无法接收为您专属推送的精选内容，我们强烈建议您不要关闭
				</view>
				<view class="li_2" @click.stop="(show = false)">取消</view>
				<view class="li_3" @click.stop="updetaUser">确定</view>
			</view>
		</view>
		<uni-popup ref="binds" mode="center">
			<view class="binds_frame">
				<view class="binds_frame_t">提示</view>
				<view class="binds_frame_c">是否确认退出？</view>
				<view class="binds_frame_b">
					<view class="cancel" @click="jcbdCancel">取消</view>
					<view class="determine" @click="confirmReceipt">确定</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="binds22" type="center" :isMaskClick="true">
			<view class="uni-popup-wrapper" style="">
				<view class="uni-popup-title"> 温馨提示 </view>
				<view class="uni-popup-content">
					<mp-html :content="html"></mp-html>
					<!-- <view class="" style="white-space: nowrap;">
						同一车牌号6个月内可绑定<text class="uni-popup-mark">3</text>次二维码
					</view>
					<view class="">
						超出将无法绑定，请谨慎操作。
					</view>
					<view class="">
						本次为第<text class="uni-popup-mark">2</text>次绑定
					</view> -->
				</view>
				<button class="uni-popup-btn-one cu-btn" @click="confirm">确定</button>
			</view>
		</uni-popup>
		<commonModalVue :modal.sync="modalData" @confirm="confirmFun" />
		<uniBall></uniBall>
	</view>
</template>
<script>
	//#ifdef H5
	import wxshare from "../utils/index.js";
	//#endif
	import {
		mapGetters
	} from "vuex";
	import commonModalVue from '../components/common-modal.vue';
	export default {
		data() {
			return {
				switchA: false,
				show: false,
				modalData:{
					show: false,
					title: '',
				},
				storageSize: "0M",
				appversion: "",
				curTop: 300,
				html: "",
				userInfo: uni.getStorageSync("Pduser"),
			};
		},
		computed: {
			...mapGetters(["statusBarHeight1", "userinfo"]),
		},
		components:{
			commonModalVue,
		},
		onLoad(options) {
			this.appversion = uni.getStorageSync("appversion");
			if (!this.appversion) {
				const system = uni.getSystemInfoSync();

				/* #ifdef H5 */
				this.appversion = system.appVersion;
				/* #endif */
				/* #ifdef APP-PLUS */
				this.appversion = system.appWgtVersion;
				/* #endif */
				/* #ifdef MP */
				this.appversion = system.version;
				/* #endif */
			}
			/* #ifdef H5 */
			this.jinzhi();
			/* #endif */
			if (this.userInfo.id) {
				this.getMsg();
			}
			this.getStorageSize(); //获取缓存
		},
		onPullDownRefresh(){
			console.log('onPullDownRefresh');
			uni.stopPullDownRefresh();
		},
		mounted() {
			let that = this;
			this.$nextTick(function() {
				uni
					.createSelectorQuery()
					.in(this)
					.select(".list")
					.boundingClientRect((result) => {
						if (result) {
							that.curTop = result.top + 70;
						}
					})
					.exec();
			});
		},
		methods: {
			toAccountSet() {
				uni.navigateTo({
					url: '/pages_my/accountManagement'
				})
			},
			switchAccounts() {
				uni.navigateTo({
					url: '/pages_my/switchAccount'
				})
			},
			// 撤回隐私
			withdrawalPrivacy() {
				let that = this;
				console.log(111);
				that.modalData = {
					show: true,
					title: '确定撤回隐私政策授权？撤回后将无法使用帮帮同城全部功能',
					confirmFun: () => {
						that.confirmReceipt();
					}
				}
			},
			confirmFun(){
				if (!this.modalData.confirmFun) {
					this.confirmReceipt();
				}
			},
			confirm() {
				this.$refs.binds22.close();
			},
			tiaozhuan(index) {
				if (index == 1) {
					uni.navigateTo({
						url: "/pages_my/report",
					});
				} else if (index == 2) {
					uni.navigateTo({
						url: "/pages_my/shield",
					});
				}
			},
			// 跳转账号注销
			clause() {
				const userInfo = uni.getStorageSync("Pduser");
				if (userInfo.merchantId) {
					// uni.showToast({
					//   title: '当前账户为车会员商家，不可注销！',
					//   icon: 'none'
					// });

					let data = {
						id: userInfo.id,
					};
					this.$myRequest
						.post("/mob/user/cancellation", data)
						.then((res) => {
							this.html = res.msg;
							this.$refs.binds22.open();
						})
						.catch((err) => {
							uni.hideToast();
							this.html = err.msg;
							this.$refs.binds22.open();
							return;
						});
					return false;
				}
				uni.navigateTo({
					url: "/pages_my/cancellation",
				});
			},
			//获取app的缓存
			getStorageSize: function() {
				let that = this;
				uni.getStorageInfo({
					success(res) {
						//console.log(res.keys);
						//console.log(res.limitSize);
						let size = res.currentSize;
						if (size < 1024) {
							that.storageSize = size + " B";
						} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
							that.storageSize = Math.floor((size / 1024) * 100) / 100 + " KB";
						} else if (size / 1024 / 1024 >= 1) {
							that.storageSize = Math.floor((size / 1024 / 1024) * 100) / 100 + " M";
						}
					},
				});
			},
			//删除 缓存
			clearStorage: function() {
				let that = this;
				uni.showModal({
					title: "提示",
					content: "确定清除缓存吗?",
					confirmText: "立即清除",
					success(res) {
						if (res.confirm) {
							// uni.clearStorageSync();
							uni.removeStorageSync("contrast");
							// uni.getStorageSync("contrast");
							//重新获取并显示清除后的缓存大小
							that.getStorageSize();
							uni.showToast({
								title: "清除成功",
								icon: "none",
							});
							// uni.navigateBack();
							//清除完后跳到登录页面
							// setTimeout(()=>{
							// 	uni.redirectTo({
							// 		url:'/pages/login/login',
							// 		animationType: 'pop-in',
							// 		animationDuration: 200
							// 	})
							// },1300)
						}
					},
				});
			},
			fanhui() {
				uni.navigateBack({
					delta: 1,
				});
			},
			xieyi(type) {
				uni.navigateTo({
					url: "/pages_my/Us?type=" + type,
				});
			},
			zzzzAncjwt(type) {
				uni.navigateTo({
					url: "/pages_my/qualification?type=" + type,
				});
			},
			getMsg() {
				let userinfo = this.userInfo
				this.$myRequest
					.get("/mob/user/queryIsMsg", {
						id: userinfo.id,
					})
					.then((res) => {
						if (res.code == 200) {
							if (res.result.isMsg === "true") {
								this.switchA = true;
							} else {
								this.switchA = false;
							}
							console.log(this.switchA);
						}
					});
			},
			us(type) {
				uni.navigateTo({
					url: "/pages_my/Us?type=" + type,
				});
			},
			SwitchA(e) {
				this.show = true;
			},
			p() {
				uni.navigateTo({
					url: "/pages_my/problem",
				});
			},
			updetaUser() {
				const userinfo = this.userInfo;
				let that = this;
				this.$myRequest
					.get("/mob/user/updateIsMsg", {
						isMsg: this.switchA ? "1" : "0",
						id: userinfo.id,
					})
					.then((res) => {
						if (res.code == 200) {
							uni.showToast({
								title: "操作成功",
								icon: "none",
							});
							that.show = false;
						}
					});
			},
			jinzhi() {
				let _this = this;
				let param = window.location.href.split("#")[0];
				uni.request({
					method: "post",
					data: {
						url: param,
					},
					header: {
						"content-type": "application/x-www-form-urlencoded",
					},
					url: "https://www.bangbangtongcheng.com/conven//mob/login/getJsTicket.do",
					success(re) {
						_this.jinzhifx(re.data);
					},
				});
			},
			jinzhifx(data) {
				wxshare.config({
					debug: false, //是否打开调试
					appId: data.appId, // 公众号的唯一标识
					timestamp: data.timestamp, // 生成签名的时间戳
					nonceStr: data.nonce, // ，生成签名的随机串
					signature: data.signature, // 签名
					jsApiList: ["hideMenuItems"],
				});
				// 禁止分享
				wxshare.hideMenuItems({
					// 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
					menuList: [
						"menuItem:share:appMessage",
						"menuItem:share:timeline",
						"menuItem:share:timeline",
						"menuItem:share:qq",
						"menuItem:favorite",
						"menuItem:share:QZone",
						"menuItem:openWithSafari",
					],
				});
			},
			jcbdCancel() {
				this.$refs.binds.close();
			},
			confirmReceipt() {
				let that = this;
				uni.removeStorageSync("Pduser");
				uni.removeStorageSync("userInfo");
				uni.removeStorageSync("sessionKey");
				uni.removeStorageSync("curriculumVitae");
				const user = uni.getStorageSync("Pduser");
				that.$store.dispatch("user/logout", {});
				// uni.navigateBack();
				this.$TOLOGIN('isLogout=1');
				// uni.navigateTo({
				// 	url: "/pages/login/login?isLogout=1",
				// });
			},
			logout() {
				let that = this;
				that.$refs.binds.open();
				//    uni.showModal({
				//      title: "提示",
				//      content: "是否确认退出？",
				//      success: function (res) {
				//        console.log(res, '点击退出登录');
				//        if (res.confirm) {
				//          console.log(res, '确认退出');
				//          // uni.removeStorage({
				//          //   key: "Pduser"
				//          // });
				//          uni.removeStorageSync("Pduser");
				//          uni.removeStorageSync("userInfo");
				// uni.removeStorageSync("sessionKey");
				//          const user = uni.getStorageSync('Pduser')
				//          console.log(user, '111111111');
				//          that.$store.dispatch("user/logout", {});
				//          uni.navigateBack();
				//        } else if (res.cancel) {}
				//      }
				//    });
				// this.$store.dispatch("user/logout", {});
				// uni.navigateBack();
			},
			clearCache() {},
		},
	};
</script>
<style lang="less" scoped>
	page {
		background: white;
	}

	.switchAccounts {
		width: 670rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		color: #fff;
		font-size: 32rpx;
		border-radius: 45rpx;
		margin: 0 auto;
		position: fixed;
		bottom: 50rpx;
		left: 50%;
		transform: translateX(-50%);
		background: #0FA291;
	}

	.touxiang {
		width: 100%;
		height: 100rpx;
		border-bottom: 2rpx solid #e0e0e0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 40rpx;

		span {
			font-size: 32rpx;
			color: #000000;
		}

		.huancun {
			display: flex;
			align-items: center;
		}

		.img2 {
			width: 18rpx;
			height: 35rpx;
		}

		/deep/uni-switch .uni-switch-input.uni-switch-input-checked {
			background-color: #3ab34a !important;
		}

		/deep/ uni-switch::after,
		uni-switch::before {
			content: "";
		}

		/deep/uni-switch .wx-switch-input,
		/deep/uni-switch .uni-switch-input {
			width: 104rpx;
			height: 62rpx;
			background-color: #8799a3 !important;
		}

		/deep/uni-switch .wx-switch-input::after,
		/deep/uni-switch .uni-switch-input::after {
			width: 60rpx;
			height: 62rpx;
		}
	}

	.box {
		width: 100%;
		min-height: 100vh;
		padding-bottom: 160rpx;
		//background-color: #fff;
		background-image: url('https://pic.bangbangtongcheng.com/userset-bg.png');
		background-size: 100% 100%;
		background-position: center;
		background-repeat: no-repeat;
		.list {
			padding-bottom: 20rpx;
		}
	}

	.tou {
		position: relative;
		width: 100%;
		text-align: center;
		line-height: 88rpx;
		font-size: 36rpx;
		color: black;
		font-weight: bold;
		//background-color: #64b6a8;

		.image1 {
			position: absolute;
			width: 32rpx;
			height: 32rpx;
			// top: 116rpx;
			left: 30rpx;
		}

		.image2 {
			position: absolute;
			width: 56rpx;
			height: 56rpx;
			// top: 104rpx;
			right: 30rpx;
		}
	}

	.logout {
		width: 690rpx;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		color: #fff;
		font-size: 30rpx;
		border-radius: 10rpx;
		margin: 0 auto;
		position: fixed;
		bottom: 20rpx;
		left: 50%;
		transform: translateX(-50%);
		background: #64b6a8;
	}

	.motaikuang {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.4);
		z-index: 20;

		.verify {
			position: fixed;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
		}

		.shangjia {
			position: absolute;
			width: 600rpx;
			// height: 300rpx;
			background-color: #fff;
			border-radius: 10rpx;
			top: 30%;
			left: 50%;
			transform: translateX(-50%);
			padding-bottom: 50rpx;

			.li_1 {
				width: 100%;
				font-size: 34rpx;
				font-weight: 600;
				// margin-left: 114rpx;
				margin: 0 auto;
				margin-top: 80rpx;
				width: 425rpx;
			}

			.li_2 {
				display: inline-block;
				vertical-align: top;
				width: 160rpx;
				height: 60rpx;
				background: #ffffff;
				border: 2rpx solid #64b6a8;
				border-radius: 37rpx;
				text-align: center;
				line-height: 60rpx;
				color: #64b6a8;
				margin-top: 58rpx;
				margin-left: 118rpx;
			}

			.li_3 {
				display: inline-block;
				vertical-align: top;
				width: 160rpx;
				height: 60rpx;
				background: #64b6a8;
				border-radius: 37rpx;
				text-align: center;
				line-height: 60rpx;
				color: #fff;
				margin-top: 58rpx;
				margin-left: 46rpx;
			}
		}
	}

	.binds_frame {
		width: 600rpx;
		background-color: #ffffff;
		// padding-bottom: 50rpx;
		border-radius: 20rpx;
		text-align: center;
		font-size: 36rpx;
		overflow: hidden;

		.binds_frame_t {
			font-weight: 550;
			color: #000000;
			padding: 0 46rpx;
			padding-top: 36rpx;
		}

		.binds_frame_c {
			width: 500rpx;
			margin: 0 auto;
			font-weight: 500;
			color: #000000;
			margin-top: 30rpx;
			margin-bottom: 50rpx;
		}

		.binds_frame_b {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.cancel {
				flex: 1;
				height: 90rpx;
				border: 1px solid #eee;
				border-radius: 10rpx 0 0 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-weight: 400;
				color: #999999;
			}

			.determine {
				flex: 1;
				height: 90rpx;
				border: 1px solid #eee;
				border-radius: 0 10rpx 10rpx 0;
				display: flex;
				align-items: center;
				justify-content: center;
				font-weight: 400;
				color: #0FA291;
			}
		}
	}

	.uni-popup-wrapper {
		width: 600rpx;
		background: #ffffff;
		border-radius: 10rpx;
		opacity: 1;
		padding: 0 32rpx;
		text-align: center;
		overflow: hidden;
	}

	.uni-popup-title {
		margin-top: 32rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
		line-height: 30rpx;
	}

	.uni-popup-content {
		padding: 30rpx 32rpx 40rpx 32rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		line-height: 42rpx;
	}

	.uni-popup-btn-one {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		background: #64b6a8;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		opacity: 1;
		font-size: 30rpx;
		font-weight: 400;
		color: #ffffff;
		line-height: 30rpx;
		margin-bottom: 32rpx;
	}
</style>